package {
	import com.rational.serialization.json.JSON;
	import org.flexunit.Assert;
	public class JSONDateTest {

		[Test(description="This tests a single untyped date")]
		public function singleUntypedDate():void {
			var date:Date = JSON.decode('["time",123]');
			Assert.assertTrue(date is Date);
			Assert.assertEquals(123, date.time);
		}

		[Test(description="This tests a single typed date")]
		public function singleTypedDate():void {
			var date:Date = JSON.decode('["time",123]', Date);
			Assert.assertTrue(date is Date);
			Assert.assertEquals(123, date.time);

			date = JSON.decode('{"time":456}', Date);
			Assert.assertTrue(date is Date);
			Assert.assertEquals(456, date.time);
		}

		[Test(description="This tests a non-date")]
		public function manyUntypedDates():void {
			var array:Array = JSON.decode('["time",123,"not date"]');
			Assert.assertTrue(array is Array);
			Assert.assertEquals(3, array.length);
			Assert.assertEquals("time", array[0]);
			Assert.assertEquals(123, array[1]);
			Assert.assertEquals("not date", array[2]);

			array = JSON.decode('["time","other"]');
			Assert.assertTrue(array is Array);
			Assert.assertEquals(2, array.length);
			Assert.assertEquals("time", array[0]);
			Assert.assertEquals("other", array[1]);
		}
	}
}